package mo_gorm

import (
	"MoSkeleton/framework/core/config/properties_db"
	"gorm.io/gorm"
)

// Mssql数据库
type MoMssqlDb struct {
}

func (m *MoMssqlDb) GenDb(dbConfig *properties_db.GeneralDBProvider) (db *gorm.DB) {
	var dbProvider properties_db.GeneralDBProvider = *dbConfig
	if mssqlConfig, ok := dbProvider.(*properties_db.Mssql); ok {
		return m.genMssqlByConfig(mssqlConfig)
	}
	panic("dbConfig is not mssql")
}

func (m *MoMssqlDb) genMssqlByConfig(dbConfig *properties_db.Mssql) *gorm.DB {
	//if dbConfig.Dbname == "" {
	//	return nil
	//}
	//mssqlConfig := sqlserver.Config{
	//	DSN:               dbConfig.Dsn(), // DSN data source name
	//	DefaultStringSize: 191,            // string 类型字段的默认长度
	//}
	//if db, err := gorm.Open(sqlserver.New(mssqlConfig), gormConfig(dbConfig.GeneralDB, dbConfig.Prefix, dbConfig.Singular)); err != nil {
	//	panic(err)
	//} else {
	//	db.InstanceSet("gorm:table_options", "ENGINE="+dbConfig.Engine)
	//	sqlDB, _ := db.DB()
	//	sqlDB.SetMaxIdleConns(dbConfig.MaxIdleConns)
	//	sqlDB.SetMaxOpenConns(dbConfig.MaxOpenConns)
	//	return db
	//}
	panic("uncomment up codes")
}
